package com.vhall.component.controller.notice;


import com.alibaba.fastjson.JSONObject;
import com.vhall.component.controller.notice.facade.NoticeInnerFacade;
import com.vhall.component.entity.notice.NoticesEntity;
import com.vhall.component.entity.notice.vo.RedPacketNoticeVo;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.service.notice.NoticesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xianglei
 * @date 2021/6/9 15:47
 */
@VhallComponent
public class NoticeInnerController implements NoticeInnerFacade {

    @Autowired
    private NoticesService noticesService;

    @Override
    public RedPacketNoticeVo addRpNotice(RedPacketNoticeVo vo) {
        RedPacketNoticeVo result = new RedPacketNoticeVo();

        NoticesEntity entity = noticesService.addRpNotice(vo);
        BeanUtils.copyProperties(entity, result);
        result.setRpUuid(entity.getRedPacketUuid());
        result.setNoticeId(entity.getId());
        return result;
    }

    @Override
    public RedPacketNoticeVo getRpNotice(String rpUuid) {
        RedPacketNoticeVo result = new RedPacketNoticeVo();

        NoticesEntity entity = noticesService.getRpNotice(rpUuid);
        BeanUtils.copyProperties(entity, result);
        result.setRpUuid(entity.getRedPacketUuid());
        result.setNoticeId(entity.getId());
        return result;
    }

    @Override
    public RedPacketNoticeVo updateRpNotice(RedPacketNoticeVo vo) {
        RedPacketNoticeVo result = new RedPacketNoticeVo();
        NoticesEntity entity = noticesService.updateRpNotice(vo);
        BeanUtils.copyProperties(entity, result);
        result.setRpUuid(entity.getRedPacketUuid());
        result.setNoticeId(entity.getId());
        return result;
    }


    @Override
    public JSONObject sendNoticeToPaas(String roomId, String content, Integer accountId, String type) {
        return noticesService.sendNotice(roomId, content, accountId, type);
    }
}
